home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / gtlayout-Source.lha / LTP_Clone.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-01  |  7.7 KB  |  302 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1994 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. #ifdef DO_CLONING
  10. VOID __regargs
  11. LTP_CloneScreen(struct LayoutHandle *Handle,LONG Width,LONG Height)
  12. {
  13.     struct ColorSpec    *ColourSpec    = NULL;
  14.     struct ColourRecord    *ColourRecord    = NULL;
  15.     struct CloneExtra    *Extra = Handle -> CloneExtra;
  16.     LONG             AllocationSize;
  17.     UWORD             i,j,*Pens = Handle -> CloneExtra -> ScreenPens,NumColours;
  18.     struct Screen        *Screen;
  19.     ULONG             DisplayID = GetVPModeID(&Handle -> Screen -> ViewPort);
  20.     UWORD             EndPen = (UWORD)~0;
  21.  
  22.     if(Handle -> ExactClone)
  23.         NumColours = Handle -> Screen -> ViewPort . ColorMap -> Count;
  24.     else
  25.     {
  26.         NumColours = Extra -> TotalPens;
  27.  
  28.         DisplayID &= ~(HAM | EXTRA_HALFBRITE);
  29.     }
  30.  
  31.     Height += Handle -> Screen -> BarHeight + 1;
  32.  
  33.     if(Width < Extra -> MinWidth)
  34.         Width = Extra -> MinWidth;
  35.  
  36.     if(Height < Extra -> MinHeight)
  37.         Height = Extra -> MinHeight;
  38.  
  39.     if(Handle -> SimpleClone)
  40.         Pens = &EndPen;
  41.     else
  42.     {
  43.         if(V39)
  44.         {
  45.             if(!(ColourRecord = (struct ColourRecord *)AsmAllocPooled(Handle -> Pool,AllocationSize = sizeof(struct ColourRecord) + sizeof(struct ColourTriplet) * NumColours,SysBase)))
  46.             {
  47.                 Handle -> Failed = TRUE;
  48.  
  49.                 return;
  50.             }
  51.             else
  52.             {
  53.                 memset(ColourRecord,0,AllocationSize);
  54.  
  55.                 ColourRecord -> NumColours = NumColours;
  56.  
  57.                 if(Handle -> ExactClone)
  58.                     GetRGB32(Handle -> Screen -> ViewPort . ColorMap,0,NumColours,(ULONG *)ColourRecord -> Triplets);
  59.                 else
  60.                 {
  61.                     for(i = 0 ; i < NumColours ; i++)
  62.                         GetRGB32(Handle -> Screen -> ViewPort . ColorMap,Extra -> Pens[i],1,(ULONG *)&ColourRecord -> Triplets[i]);
  63.                 }
  64.             }
  65.         }
  66.         else
  67.         {
  68.             if(!(ColourSpec = (struct ColorSpec *)AsmAllocPooled(Handle -> Pool,AllocationSize = sizeof(struct ColorSpec) * (NumColours + 1),SysBase)))
  69.             {
  70.                 Handle -> Failed = TRUE;
  71.  
  72.                 return;
  73.             }
  74.             else
  75.             {
  76.                 UWORD RGB;
  77.  
  78.                 if(Handle -> ExactClone)
  79.                 {
  80.                     for(i = 0 ; i < NumColours ; i++)
  81.                     {
  82.                         RGB = GetRGB4(Handle -> Screen -> ViewPort . ColorMap,i);
  83.  
  84.                         ColourSpec[i] . ColorIndex    = i;
  85.                         ColourSpec[i] . Red        = (RGB >> 8) & 0xF;
  86.                         ColourSpec[i] . Green        = (RGB >> 4) & 0xF;
  87.                         ColourSpec[i] . Blue        = (RGB       ) & 0xF;
  88.                     }
  89.                 }
  90.                 else
  91.                 {
  92.                     for(i = 0 ; i < NumColours ; i++)
  93.                     {
  94.                         RGB = GetRGB4(Handle -> Screen -> ViewPort . ColorMap,Extra -> Pens[i]);
  95.  
  96.                         ColourSpec[i] . ColorIndex    = i;
  97.                         ColourSpec[i] . Red        = (RGB >> 8) & 0xF;
  98.                         ColourSpec[i] . Green        = (RGB >> 4) & 0xF;
  99.                         ColourSpec[i] . Blue        = (RGB       ) & 0xF;
  100.                     }
  101.                 }
  102.  
  103.                 ColourSpec[i] . ColorIndex = -1;
  104.             }
  105.         }
  106.  
  107.         if(Handle -> ExactClone)
  108.         {
  109.             for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  110.                 Pens[i] = Extra -> Pens[i];
  111.         }
  112.         else
  113.         {
  114.             for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  115.             {
  116.                 for(j = 0 ; j < NumColours ; j++)
  117.                 {
  118.                     if(Extra -> Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
  119.                     {
  120.                         Pens[i] = j;
  121.  
  122.                         break;
  123.                     }
  124.                 }
  125.             }
  126.         }
  127.  
  128.         Pens[i] = (UWORD)~0;
  129.     }
  130.  
  131.     if(Screen = OpenScreenTags(NULL,
  132.         SA_Width,    Width,
  133.         SA_Height,    Height,
  134.         SA_Overscan,    OSCAN_TEXT,
  135.         SA_AutoScroll,    TRUE,
  136.         SA_DisplayID,    DisplayID,
  137.         SA_Behind,    TRUE,
  138.         SA_Depth,    Handle -> SimpleClone ? 2 : Extra -> Depth,
  139.         SA_Colors,    ColourSpec,
  140.         SA_Colors32,    ColourRecord,
  141.         SA_Pens,    Pens,
  142.         SA_Font,    Handle -> TextAttr,
  143.         SA_Title,    Handle -> Screen -> DefaultTitle,
  144.  
  145.         Handle -> SimpleClone ? TAG_IGNORE : SA_BackFill,    &Handle -> BackfillHook,
  146.         Handle -> SimpleClone ? TAG_IGNORE : SA_BlockPen,    Pens[SHADOWPEN],
  147.         Handle -> SimpleClone ? TAG_IGNORE : SA_DetailPen,    Pens[BACKGROUNDPEN],
  148.     TAG_DONE))
  149.     {
  150.         struct DrawInfo *DrawInfo;
  151.  
  152.         if(DrawInfo = GetScreenDrawInfo(Screen))
  153.         {
  154.             APTR VisualInfo;
  155.  
  156.             if(VisualInfo = GetVisualInfoA(Screen,NULL))
  157.             {
  158.                 UnlockPubScreen(NULL,Handle -> PubScreen);
  159.  
  160.                 FreeScreenDrawInfo(Handle -> Screen,Handle -> DrawInfo);
  161.  
  162.                 FreeVisualInfo(Handle -> VisualInfo);
  163.  
  164.                 Handle -> PubScreen    = NULL;
  165.                 Handle -> Screen    = Screen;
  166.                 Handle -> DrawInfo    = DrawInfo;
  167.                 Handle -> VisualInfo    = VisualInfo;
  168.                 Handle -> TextPen    = Handle -> DrawInfo -> dri_Pens[TEXTPEN];
  169.                 Handle -> BackgroundPen = Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN];
  170.                 Handle -> ShinePen    = Handle -> DrawInfo -> dri_Pens[SHINEPEN];
  171.                 Handle -> ShadowPen    = Handle -> DrawInfo -> dri_Pens[SHADOWPEN];
  172.                 Handle -> AspectX    = Handle -> DrawInfo -> dri_Resolution . X;
  173.                 Handle -> AspectY    = Handle -> DrawInfo -> dri_Resolution . Y;
  174.  
  175.                 if(Handle -> SimpleClone)
  176.                     Handle -> MaxPen = 0;
  177.                 else
  178.                     Handle -> MaxPen = Extra -> TotalPens - 1;
  179.  
  180.                 Extra -> Screen = Screen;
  181.  
  182.                 if(ColourRecord)
  183.                     AsmFreePooled(Handle -> Pool,ColourRecord,AllocationSize,SysBase);
  184.  
  185.                 if(ColourSpec)
  186.                     AsmFreePooled(Handle -> Pool,ColourSpec,AllocationSize,SysBase);
  187.  
  188.                 return;
  189.             }
  190.  
  191.             FreeScreenDrawInfo(Screen,DrawInfo);
  192.         }
  193.  
  194.         CloseScreen(Screen);
  195.     }
  196.  
  197.     if(ColourRecord)
  198.         AsmFreePooled(Handle -> Pool,ColourRecord,AllocationSize,SysBase);
  199.  
  200.     if(ColourSpec)
  201.         AsmFreePooled(Handle -> Pool,ColourSpec,AllocationSize,SysBase);
  202.  
  203.     Handle -> Failed = TRUE;
  204. }
  205.  
  206. BOOLEAN __regargs
  207. LTP_PrepareCloning(struct LayoutHandle *Handle)
  208. {
  209.     if(Handle -> CloneExtra)
  210.         return(TRUE);
  211.     else
  212.     {
  213.         struct DimensionInfo DimensionInfo;
  214.  
  215.         if(GetDisplayInfoData(NULL,(APTR)&DimensionInfo,sizeof(struct DimensionInfo),DTAG_DIMS,GetVPModeID(&Handle -> Screen -> ViewPort)))
  216.         {
  217.             if(Handle -> CloneExtra = (struct CloneExtra *)AsmAllocPooled(Handle -> Pool,sizeof(struct CloneExtra) + (sizeof(LONG) + sizeof(UWORD)) * Handle -> DrawInfo -> dri_NumPens + sizeof(UWORD),SysBase))
  218.             {
  219.                 UWORD     i,j,TotalPens = 0;
  220.                 LONG    *Pens;
  221.                 BOOLEAN  NotFound;
  222.  
  223.                 Handle -> CloneExtra -> Pens        = (LONG *)(Handle -> CloneExtra + 1);
  224.                 Handle -> CloneExtra -> ScreenPens    = (UWORD *)(&Handle -> CloneExtra -> Pens[Handle -> DrawInfo -> dri_NumPens]);
  225.                 Handle -> CloneExtra -> MinWidth    = DimensionInfo . MinRasterWidth;
  226.                 Handle -> CloneExtra -> MinHeight    = DimensionInfo . MinRasterHeight;
  227.                 Handle -> CloneExtra -> MaxWidth    = DimensionInfo . MaxRasterWidth;
  228.                 Handle -> CloneExtra -> MaxHeight    = DimensionInfo . MaxRasterHeight;
  229.  
  230.                 Handle -> CloneExtra -> Bounds . Left    = 0;
  231.                 Handle -> CloneExtra -> Bounds . Top    = 0;
  232.                 Handle -> CloneExtra -> Bounds . Width    = DimensionInfo . MaxRasterWidth;
  233.                 Handle -> CloneExtra -> Bounds . Height = DimensionInfo . MaxRasterHeight;
  234.  
  235.                 Pens = Handle -> CloneExtra -> Pens;
  236.  
  237.                 if(Handle -> ExactClone)
  238.                 {
  239.                     for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  240.                         Pens[i] = Handle -> DrawInfo -> dri_Pens[i];
  241.  
  242.                     TotalPens = Handle -> DrawInfo -> dri_NumPens;
  243.  
  244.                     Handle -> CloneExtra -> Depth = Handle -> DrawInfo -> dri_Depth;
  245.                 }
  246.                 else
  247.                 {
  248.                     for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  249.                     {
  250.                         for(j = 0,NotFound = TRUE ; NotFound && j < TotalPens ; j++)
  251.                         {
  252.                             if(Pens[j] == Handle -> DrawInfo -> dri_Pens[i])
  253.                                 NotFound = FALSE;
  254.                         }
  255.  
  256.                         if(NotFound)
  257.                             Pens[TotalPens++] = Handle -> DrawInfo -> dri_Pens[i];
  258.                     }
  259.  
  260.                     for(i = 0 ; i < DimensionInfo . MaxDepth ; i++)
  261.                     {
  262.                         if(TotalPens <= (1L << i))
  263.                         {
  264.                             Handle -> CloneExtra -> Depth = i;
  265.  
  266.                             break;
  267.                         }
  268.                     }
  269.                 }
  270.  
  271.                 if((Handle -> CloneExtra -> TotalPens = TotalPens) && Handle -> CloneExtra -> Depth)
  272.                 {
  273.                     if(LTP_GlyphSetup(Handle,Handle -> InitialTextAttr))
  274.                     {
  275.                         Handle -> Failed = Handle -> Rescaled = FALSE;
  276.  
  277.                         LTP_ResetGroups(Handle -> TopGroup);
  278.  
  279.                         if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
  280.                         {
  281.                             LTP_Rescale(Handle,FALSE,FALSE);
  282.  
  283.                             Handle -> Rescaled = FALSE;
  284.                         }
  285.  
  286.                         return(TRUE);
  287.                     }
  288.                 }
  289.                 else
  290.                 {
  291.                     AsmFreePooled(Handle -> Pool,Handle -> CloneExtra,sizeof(struct CloneExtra) + sizeof(LONG) * Handle -> DrawInfo -> dri_NumPens,SysBase);
  292.  
  293.                     Handle -> CloneExtra = NULL;
  294.                 }
  295.             }
  296.         }
  297.     }
  298.  
  299.     return(FALSE);
  300. }
  301. #endif
  302.